<?php
$this->breadcrumbs=array(
	'Pages'=>array('index'),
);

$params = array('id' => $model->id);
if ($layout = Yii::app()->request->getParam('layout', false))
    $params['layout'] = $layout;

$tabs = array(
    'Details'=>$this->renderPartial('details',array(
        'model'=>$model, 
        'pageUrls'=>$pageUrls, 
        'pageRevision'=>$pageRevision,
    ), true)
);
if ($model->id)
{
    $this->breadcrumbs = CMap::mergeArray($this->breadcrumbs, array($model->title=>array('update','id'=>$model->id),'Update'));
    echo "<h2>Edit Page {$model->title}</h2>";
    
    if (Yii::app()->request->getQuery('layout', '') !== 'popup')
    {
        $tabs['URLs'] = array('ajax'=>$this->createUrl('url', array('page_id'=>$model->id)));
        $tabs['Revisions'] = array('ajax'=>$this->createUrl('/Cms/admin/pageRevision/admin', array('page_id'=>$model->id)));
        $tabs['Content'] = array('ajax'=>$this->createUrl('/Cms/admin/workflow/page', array('page_id'=>$model->id)));
    }
}
else
{
    $this->breadcrumbs[] = 'Create';
    echo "<h2>Create Page</h2>";
}
    
$this->widget('zii.widgets.jui.CJuiTabs', array(
    'id'=>'page-tabs',
    'tabs'=>$tabs,
    'options'=>array(
        'cache'=>true,
    )
));

$cs=Yii::app()->getClientScript();
$cs->registerScriptFile(Yii::app()->core->AssetUrl.'/scripts/gridview.js', CClientScript::POS_BEGIN);
$cs->registerScriptFile(Yii::app()->theme->baseUrl.'/scripts/fancybox/jquery.fancybox-1.3.4.pack.js');
$cs->registerCssFile(Yii::app()->theme->baseUrl.'/scripts/fancybox/jquery.fancybox-1.3.4.css');

if (isset($_GET['select']) && $_GET['select'] == 'revision')
{
    $script = "jQuery('#page-tabs').tabs('select', 2);";
    $cs->registerScript(__CLASS__.'#RevisionTab', $script, CClientScript::POS_READY);
}

$script = "
jQuery.fancyboxResize = function(height){
    jQuery('#fancybox-content').css('height', height);
    jQuery.fancybox.center(true);
}
jQuery('.add-url, .button-column .update').live('click', function(){
    jQuery.fancybox({
        'titleShow'         : false,
        'height'            : 250,
        'autoScale'         : true,
        'transitionIn'      : 'none',
        'transitionOut'     : 'none',
        'type'              : 'iframe',
        'href'              : jQuery(this).attr('href')
    });
    return false;
});
";
$cs->registerScript(__CLASS__.'#AddUrl', $script, CClientScript::POS_READY);

$script = "jQuery.reloadPageUrlTab = function(){jQuery('#page-tabs').tabs('load', 1);}";
$cs->registerScript(__CLASS__.'#ReloadPageUrl', $script, CClientScript::POS_READY);

$script = "
jQuery('.grid-view .status-column a').live('click', function(){
    if (jQuery(this).parent().hasClass('default'))
        return false;
    jQuery.get(jQuery(this).attr('href'), function(){
        jQuery('.grid-view .filters input').trigger('change');
    });
    return false;
});
";
$cs->registerScript(__CLASS__.'#ChangeStatus', $script, CClientScript::POS_READY);

$baseScriptUrl=Yii::app()->getAssetManager()->publish(Yii::getPathOfAlias('zii.widgets.assets')).'/gridview';
Yii::app()->getClientScript()->registerCssFile($baseScriptUrl.'/styles.css');
$url=CHtml::asset(Yii::getPathOfAlias('system.web.widgets.pagers.pager').'.css');
Yii::app()->getClientScript()->registerCssFile($url);

$cs->registerCoreScript('jquery');
$cs->registerCoreScript('bbq');
$cs->registerScriptFile($baseScriptUrl.'/jquery.yiigridview.js',CClientScript::POS_END);
$this->renderPartial('/admin/page/_form_copy', array('sites'=>$sites, 'pageId'=>$model->id, 'pageInfo'=>'Copy page'));